package logic

import (
	"context"
	"video/videorpc/videorpcclient"

	"video/api/internal/svc"
	"video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *VideoAddLogic) VideoAdd(req *types.VideoAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	videoAdd, err := l.svcCtx.VideoRpc.VideoAdd(l.ctx, &videorpcclient.VideoAddRequest{
		Title:      req.Title,
		Category:   req.Category,
		Link:       req.Link,
		CoverLink:  req.CoverLink,
		Intro:      req.Intro,
		PlayNum:    req.PlayNum,
		LikeNum:    req.LikeNum,
		CollectNum: req.CollectNum,
		CommentNum: req.CommentNum,
		Status:     req.Status,
		UserId:     req.UserId,
		TopicId:    req.TopicId,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "视频发布成功",
		Code:    200,
		Data:    videoAdd,
	}, nil

}
